package com.guigu.www.luolujin.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.luolujin.Service.LljTemplateWholesomeDetailsService;
import com.guigu.www.mapper.TemplateWholesomeDetailsMapper;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.pojo.TemplateWholesome;
import com.guigu.www.pojo.TemplateWholesomeDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者 罗露金
 */
@Service
public class LljTemplateWholesomeDetailsServiceImpl implements LljTemplateWholesomeDetailsService {
    @Autowired
    TemplateWholesomeDetailsMapper mapper;
    @Override
    public PageVo<TemplateWholesomeDetails> pageTemWholesomeDetails(Integer pageNum, Integer pageSize, String tempWhoDeName) {
        QueryWrapper<TemplateWholesomeDetails> wrapper = new QueryWrapper<>();
        wrapper.like("temp_who_de_name",tempWhoDeName);
        Page page = new Page(pageNum, pageSize);
        IPage iPage = mapper.selectPage(page, wrapper);
        PageVo<TemplateWholesomeDetails> pageVo = new PageVo<>();
        pageVo.setRows(iPage.getRecords());
        pageVo.setTotal(iPage.getTotal());
        return pageVo;
    }

    @Override
    public void insertTemWholesomeDetails(TemplateWholesomeDetails templateWholesomeDetails) {
        mapper.insert(templateWholesomeDetails);
    }

    @Override
    public void updateTemWholesomeDetails(TemplateWholesomeDetails templateWholesomeDetails) {
        mapper.updateById(templateWholesomeDetails);
    }

    @Override
    public void deleteTemWholesomeDetails(int tempWhoDeId) {
        mapper.deleteById(tempWhoDeId);
    }

    @Override
    public TemplateWholesomeDetails selectById(int tempWhoDeId) {
        return mapper.selectById(tempWhoDeId);
    }

    @Override
    public void upTemWholesomeDetails(Integer tempWhoDeId, Integer tempWhoDeState) {
        TemplateWholesomeDetails templateWholesomeDetails = new TemplateWholesomeDetails();
        templateWholesomeDetails.setTempWhoDeId(tempWhoDeId);
        templateWholesomeDetails.setTempWhoDeState(tempWhoDeState);
        mapper.updateById(templateWholesomeDetails);
    }

    @Override
    public List<TemplateWholesomeDetails> queryAll() {
        QueryWrapper<TemplateWholesomeDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("temp_who_de_state ",0);
        return mapper.selectList(wrapper);
    }
}
